import fetch from "./fetch";

// 判断环境。使用不同的api
// development 开发过程中的环境(测试)
// production 生产环境

// 在编译的时候执行


// 响应
// 统一类型
interface ResData<T> {
  code: number;
  msg: string;
  data: T;
}
// 列表 种植区域
export const ApiPlanting = () =>
  fetch(
    `/planting/listArea`,
    {},
    {},
    "POST"
  );

// 列表 种植树种
export const ApiListTree = (planting_area_id: number) =>
  fetch(`/planting/listTree`, { planting_area_id }, {}, "POST");
// 列表 种植树种 规格
export const ApiListTreeSpecification = (planting_tree_id: number, name: string) =>
  fetch(
    `/planting/listTreeSpecification`,
    { planting_tree_id, name },
    {},
    "POST"
  );

  // 镇列表
export const ApiSelectListAreaDistrict = () =>
  fetch(
    `/planting/selectListAreaDistrict`,
    { },
    {},
    "POST"
  );

  // 统计 捐赠记录 村
export const ApiStatisticDonateRecordArea = (planting_area_id: number) =>
  fetch(
    `/planting/statisticDonateRecordArea`,
    { planting_area_id },
    {},
    "POST"
  );
// 统计 捐赠记录 镇区
// /planting/statisticDonateRecordAreaDistrict
export const ApiStatisticDonateRecordAreaDistrict = (district: string) =>
  fetch(
    `/planting/statisticDonateRecordAreaDistrict`,
    { district },
    {},
    "POST"
  );

  // 新增捐赠记录
export const ApiAddDonateRecord = (params: {
  openid_mp: string;
  donate_total: number; //捐赠金额，合计
  donate_number: number; //捐赠数量
  donate_amount: number; //捐赠金额
  type: number; //捐赠主体类型
  name: string; //捐赠主体名称
  contact_information: string; //捐赠主体联系方式
  planting_area_id: number; //种植区域id
  planting_area_name: string; //种植区域名称
  planting_tree_id: number; //种植树种id
  planting_tree_name: string; //种植树种名称
  planting_tree_specification_id: number; //种植树种规格id
  planting_tree_specification_name: string; //种植树种规格名称
}) => fetch(`/planting/addDonateRecord`, { ...params }, {}, "POST");

// 微信捐赠 /planting/payDonateRecord
export const ApiPayDonateRecord = (params: {
  openid_mp: string;
  donate_total: number; //捐赠金额，合计
  donate_number: number; //捐赠数量
  donate_amount: number; //捐赠金额
  type: number; //捐赠主体类型
  name: string; //捐赠主体名称
  contact_information: string; //捐赠主体联系方式
  planting_area_id: number; //种植区域id
  planting_area_name: string; //种植区域名称
  planting_tree_id: number; //种植树种id
  planting_tree_name: string; //种植树种名称
  planting_tree_specification_id: number; //种植树种规格id
  planting_tree_specification_name: string; //种植树种规格名称
  planting_tree_type: string; //种植树种规格名称
}) =>
  fetch(
    `/planting/payDonateRecord`,
    { ...params, type: Number(params.type) },
    {},
    "POST"
  );

  // 获取捐赠记录
export const ApiGetDonateRecord = (openid_mp: string) =>
  fetch(`/planting/listDonateRecord`, { openid_mp: "123" }, {}, "POST");


// 获取openid /api/member-car/delete
export const ApiGetOpenId = (
  js_code: string
): Promise<ResData<{ data: { session_key: string; openid: string } }>> => {
  return fetch(`/base/WeChat/getMpOpenid`, { js_code }, {}, "POST");
};


